<?php
namespace app\rpc\common;

class ViewBaseController extends CacheRegionController{

    /**
     * 基础页面渲染类
     * @param $tpl
     * @param $data
     * @return false|string
     */
    public function display($tpl,$layouts='main'){
        $tpl = __DIR__.DR.'../view/'.$tpl.'.php';
        $layoutsTpl = __DIR__.DR.'../view/layouts/'.$layouts.'.php';
        self::$output = $this->createView($tpl);
        $display =  $this->createView($layoutsTpl);
        return $display;
    }

    protected function assign($key,$value){
        self::$assign[$key] = $value;
    }

    private function createView($dir='',$data=[]){
        $contents ='';
        if (empty($dir)) goto end;
        $this->_beginOb($data);
        $contents = $this->_output($dir);
        $this->_clean();
        end:
        return $contents;
    }

}